/* 
 * oms，一个基于J2EE架构运营支撑平台
 * Copyright © GrayRabbit Co., Ltd. All rights reserved.
 * Department:运营department
 * 更多信息请访问：
 * http://code.google.com/p/gray-rabbit-cms/
 */
package org.grayrabbit.cms.action.publish;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.grayrabbit.cms.entity.PublishLog;
import org.grayrabbit.cms.service.publish.PublishLogService;
import org.grayrabbit.cms.vo.publish.PublishLogBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import org.grayrabbit.dao.util.Page;
import org.grayrabbit.web.struts2.GenericAction;

/**
 * <b>PublishLogAction</b> Struts2 action

 * @version 1.0,创建时间:2012-01-06 13:39:16 
 */
@Controller
@Scope("prototype")
@Results( {
		@Result(name = "reload", type = "redirect",  location = "publishlog-list.action"),
		@Result(name = "input",  type = "dispatcher", location = "publishlog-input.jsp"),
		@Result(name = "success", type = "dispatcher", location = "publishlog-list.jsp")
		}
		)
public class PublishLogAction extends GenericAction<PublishLogBean> {
	private static final long serialVersionUID = -1L;
	//Service接口接入
	@Autowired
	@Qualifier("publishLogServiceImpl")
	private PublishLogService publishLogService;
	
	//VO对象，由前端页面数据组装
	private PublishLogBean publishLog;
	
	//分页对象
	private Page<PublishLog> page = new Page<PublishLog>(MAX_PAGE_NUM,true);
	
	/**
	 * 在执行（struts2的action调用时）list()方法前执行本方法
	 */
	public void prepareList(){
		prepareModel();
	}
	
	/**
	 * 在执行任何其它action方法（struts2的action调用时）前执行本方法
	 */
	public void prepare(){
		if(publishLog==null){
			publishLog = new PublishLogBean();
		}
	}
	/**
	 * 实现ModelDriven的接口简例前端页的bean组装写法,
	 *  如：
	 *	<pre>
	 *		<code> name="user.userName"</code>
	 *	改写成：
	 *		<code> name="userName"</code>
	 *	action实例中，会自动组成user成员变量
	 *	</pre>
	 */
	public PublishLogBean getModel() {
		return publishLog;
	}
	
	@Override
	protected void prepareModel(){
		if(publishLog != null && StringUtils.isNotBlank(publishLog.getPublishLogId())){
			publishLog = (PublishLogBean)dozer.map(publishLogService.getPublishLog(publishLog.getPublishLogId()),PublishLogBean.class);
		}
	}

	/**
	 * 删除<b>PublishLog</b>记录的方法，成员变量<b>key</b>为主键的String数组，以主键方式进行删作
	 * 删除成功后，返回"reload"，然后跳转到publishlog-list.action
	 */
	@Override
	@Action(value="publishlog-delete",
			results={@Result(name="reload",type="redirectAction",params={"actionName","publishlog-list"})}
			)
	public String delete(){
		publishLogService.delete(key);
		return RELOAD;
	}
	
	/**
	 * PublishLog的列表方法，通过成员变量<b>page�?{insClassName}</b>调用service接口，更新page
	 * 执行成功后，将映射到publishlog-list.jsp页面
	 */
	@Override
	@Action(value="publishlog-list")
	public String list(){
		publishLogService.list(page,publishLog);
		return SUCCESS;
	}
	/**
	 * PublishLog的新增与编辑的方法执行成功能
	 * 将映射到publishlog-input.jsp
	 */
	@Action(value="publishlog-input")
	public String input(){
		prepareModel();
		return INPUT;
	}
	
	/**
	 * save or update PublishLog的方法，将成员property publishLog转成PublishLog实例，执行保存；
	 * 执行成功后，返回"reload"，然后跳转到publishlog-list.action
	 */
	@Override
	@Action(value="publishlog-save",
			results={@Result(name="reload",type="redirectAction",params={"actionName","publishlog-list"})}
		)
	public String save(){
		PublishLog obj = (PublishLog) dozer.map(publishLog, PublishLog.class);
		if(!StringUtils.isNotBlank(obj.getPublishLogId())){
			obj.setPublishLogId(null);
		}
		publishLogService.save(obj);
		return RELOAD;
	}
	
	
		/**return 前端页面数据组装VO对象,<b>PublishLogBean</b>*/
	public PublishLogBean getPublishLog() {
		return publishLog;
	}

	public void setPublishLog(PublishLogBean publishLog) {
		this.publishLog = publishLog;
	}
	
	/*
	 * return分页对象，默认实例化。如：page.pageNu=2,将更新相应的对象property
	 */
	public Page<PublishLog> getPage() {
		return page;
	}
	//接收前端form,url提交参数组装成分页property
	public void setPage(Page<PublishLog> page) {
		this.page = page;
	}
}